package com.yfs.cloud.commons;

import java.util.regex.Pattern;

/**
 * @Company: 影法師工作室
 * @Description: 项目的通用常量类, 子工程如果也有自己的常量类的话, 请继承本类
 * @author 影法師
 * @date 2020年8月24日 下午4:12:22
 * @version V1.0
 */
public abstract class Constants {
	/*
	 * ================================ResultCode相关常量===============================
	 */

	/** SUCCESS的状态码和信息 */
	public static final int SUCCESS_CODE = 100;
	public static final String SUCCESS_MSG = "成功";

	/** 系统异常开始 */

	/** SYSTEM_ERROR的状态码和信息 */
	public static final int SYSTEM_ERROR_CODE = 900;
	public static final String SYSTEM_ERROR_MSG = "系统开小差了, 请稍后再试";

	/** 网关404 */
	public static final String NOT_FOUND_MSG = "您的请求飞走了";

	/** 系统异常结束 */

	/** 业务异常开始 */

	/** USER_LOGIN_FAILED 的状态码和信息 */
	public static final int USER_LOGIN_FAILED_CODE = 501;
	public static final String USER_LOGIN_FAILED_MSG = "用户名登录失败, 用户名或者密码错误";

	/** JWT_INVALID的状态码和信息 */
	public static final int JWT_INVALID_CODE = 502;
	public static final String JWT_INVALID_MSG = "登陆令牌非法";

	/** JWT_EXPIRE的状态码和信息 */
	public static final int JWT_EXPIRE_CODE = 503;
	public static final String JWT_EXPIRE_MSG = "登陆令牌过期,请重新登录";

	/** APIIDEMPOTENT_REPEAT_COMMIT的状态码和信息 */
	public static final int APIIDEMPOTENT_REPEAT_COMMIT_CODE = 504;
	public static final String APIIDEMPOTENT_REPEAT_COMMIT_MSG = "短时间内请不要重复调用接口";

	/** APIIDEMPOTENT_TOKEN_EMPTY的状态码和信息 */
	public static final int APIIDEMPOTENT_TOKEN_EMPTY_CODE = 505;
	public static final String APIIDEMPOTENT_TOKEN_EMPTY_MSG = "接口幂等令牌缺失";

	/** JWT_EMPTY的状态码和信息 */
	public static final int JWT_EMPTY_CODE = 506;
	public static final String JWT_EMPTY_MSG = "登陆令牌缺失";

	/** ACCESS_DENY的状态码和信息 */
	public static final int ACCESS_DENY_CODE = 507;
	public static final String ACCESS_DENY_MSG = "权限不足";

	public static final int AUTHCHECKER_NOT_REGULAR_CODE = 508;
	public static final String AUTHCHECKER_NOT_REGULAR_MSG = "数据接口鉴权类没有实现AuthChecker接口,请联系开发人员";

	public static final int SMS_SEND_FAILED_CODE = 509;
	public static final String SMS_SEND_FAILED_MSG = "短信验证码发送失败";

	public static final int PHONE_ERROR_CODE = 510;
	public static final String PHONE_ERROR_MSG = "手机号码格式不正确";

	public static final int XSS_ATTACK_CODE = 511;
	public static final String XSS_ATTACK_MSG = "提交内容包含XSS攻击";

	/** 业务异常结束 */

	/** 校验异常开始 */

	/** PARAM_IS_INVALID的状态码和信息 */
	public static final int PARAM_IS_INVALID_CODE = 600;
	public static final String PARAM_IS_INVALID_MSG = "入参未通过校验";

	/** 校验异常结束 */

	/** Assert 异常开始 */

	/** ASSERT_FAILED的状态码 */
	public static final int ASSERT_FAILED_CODE = 700;

	public static final String PAGE_NUM_INVALID = "页号非法";

	public static final String PAGE_SIZE_INVALID = "页大小非法";

	public static final String USER_NOT_EXIST = "用户不存在";

	public static final String CAPTCHA_ERROR = "验证码输入错误";

	public static final String PHONE_EMPTY = "手机号为空";

	public static final String WX_OPENID_EMPTY = "微信openid为空";

	public static final String USERNAME_EMPTY = "用户名为空";

	public static final String USER_ID_EMPTY = "用户ID为空";

	public static final String GOODSID_EMPTY = "商品id为空";

	public static final String ORDERNO_EMPTY = "订单号为空";

	/** Assert 异常结束 */

	/*
	 * =================================其他常量========================================
	 */

	/** 幂等token, 前端需要在http头中放置一个名为 APIIDEMPOTENT_TOKEN 的头 */
	public static final String APIIDEMPOTENT_TOKEN = "APIIDEMPOTENT_TOKEN";

	/** jwt 头 , 前端需要放一个名为 Authorization 东西进入http 请求头中 */
	public static final String JWT_HEADER = "Authorization";

	/** 微服务网关转发微服务的请求中带的的用户id头部 */
	public static final String USER_ID = "USER_ID";

	/** jwt 令牌中的颁发者 */
	public static final String JWT_SUBJECT = "kmax";

	/** feign调用时传递的头部, AuthInterceptor 就不去拦截此feign调用了 */
	public static final String FEIGN_INNER = "FEIGN_INNER";

	/**
	 * 请求在微服务之间传递的时候, 将用户拥有的角色、权限信息放入头部进行传递, 这样下游微服务如果检查到了这个头的存在的话,
	 * 就不需要再去调用userFeign去查询用户角色、权限信息了, 也就是说, 每次微服务调用链只需要查询一次用户拥有的角色、权限信息,
	 * 但是弊端是角色、权限复杂的系统这个头可能比较长, 优化方案就是缓存, 不管是对用户微服务查询用户角色、权限的接口进行缓存还是将这些信息丢到redis中去
	 */
	public static final String USER_AUTHORITY_HEADER = "USER_AUTHORITY_HEADER";

	/** 允许所有的角色访问此数据接口 */
	public static final String ROLE_ALL = "ROLE_ALL";

	/** 手机号校验正则表达式 */
	public static final Pattern PHONE_PATTERN = Pattern
			.compile("^((13[0-9])|(15[^4])|(18[0,2,3,5-9])|(17[0-8])|(147))\\d{8}$");

	/** 微信扫码登录生成的二维码, 即微信开放平台授权baseUrl %s相当于 ? 代表占位符 */
	public static final String WX_QR_CODE_GENERATE_URL = "https://open.weixin.qq.com/connect/qrconnect" + "?appid=%s"
			+ "&redirect_uri=%s" + "&response_type=code" + "&scope=snsapi_login" + "&state=%s" + "#wechat_redirect";

	/** 微信用于获取access_token的地址 */
	public static final String WX_GET_ACCESS_TOKEN_URL = "https://api.weixin.qq.com/sns/oauth2/access_token"
			+ "?appid=%s" + "&secret=%s" + "&code=%s" + "&grant_type=authorization_code";

	/** 通过 access_token 和 openid 去获取微信用户的基本信息, 例如微信昵称、微信头像等等 */
	public static final String WX_GET_USERINFO_URL = "https://api.weixin.qq.com/sns/userinfo" + "?access_token=%s"
			+ "&openid=%s";

	/** 微信支付统一下单地址 */
	public static final String WX_PAY_UNIFIEDORDER = "https://api.mch.weixin.qq.com/pay/unifiedorder";

	/** 微信支付统一查询订单地址 */
	public static final String WX_PAY_ORDERQUERY = "https://api.mch.weixin.qq.com/pay/orderquery";

	/** 订单状态尚未支付 */
	public static final Byte ORDER_STATUS_NOT_PAY = 0;

	/** 订单状态已经支付 */
	public static final Byte ORDER_STATUS_HAS_PAYED = 1;

	/** 订单支付类型之微信 */
	public static final Byte ORDER_PAY_TYPE_WX = 1;

	/** 订单支付类型之支付宝 */
	public static final Byte ORDER_PAY_TYPE_ALIPAY = 2;

	public static final String PAY_FAILED = "支付失败";

	public static final String PAY_SUCCESS = "支付成功";

	public static final String PAY_ING = "支付中";

	public static final String COMMA = ",";

	public static final String PERCENT = "%";

	public static final String APPLICATION_YML = "application.yml";

	public static final String PAGE_SIZE = "pageSize";

	public static final String PAGE_NUM = "pageNum";

}
